package com.sjyl.kaoshitong.witget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import com.sjyl.kaoshitong.R;
import com.sjyl.kaoshitong.util.Utility;

/**
 * Created by ChangerLow on 15/7/18.
 * Email: changerlow@qq.com
 */
public class MoreContextMenu extends LinearLayout implements View.OnClickListener {
    private static final int CONTEXT_MENU_WIDTH = Utility.dp2Px(240);
    private int feedItem = -1;
    private Button reportBtn;
    private Button openBtn;
    private Button starBtn;
    private Button cancelBtn;
    private Button ratingBtn;



    private OnMoreContextMenuItemClickListener onItemClickListener;

    public MoreContextMenu(Context context) {
        super(context);
        init();
    }

    private void init() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.view_context_menu, this, true);
        setBackgroundResource(R.drawable.bg_container_shadow);
        setOrientation(VERTICAL);
        setLayoutParams(new LayoutParams(CONTEXT_MENU_WIDTH, ViewGroup.LayoutParams.WRAP_CONTENT));
        reportBtn = (Button)view.findViewById(R.id.btn_report);
        reportBtn.setOnClickListener(this);
        openBtn = (Button)view.findViewById(R.id.btn_open);
        openBtn.setOnClickListener(this);
        starBtn = (Button)view.findViewById(R.id.btn_star);
        starBtn.setOnClickListener(this);
        cancelBtn = (Button)view.findViewById(R.id.btn_cancel);
        cancelBtn.setOnClickListener(this);
        ratingBtn = (Button)view.findViewById(R.id.btn_rating);
        ratingBtn.setOnClickListener(this);
    }

    public void bindToItem(int feedItem) {
        this.feedItem = feedItem;
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
    }

    public void dismiss() {
        ((ViewGroup) getParent()).removeView(MoreContextMenu.this);
    }
    /**
     * Created by ChangerLow on 15/6/30.
     * Email: changerlow@qq.com
     */public void setOnMoreMenuItemClickListener(OnMoreContextMenuItemClickListener onMoreClickListener) {
        this.onItemClickListener = onMoreClickListener;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_open:
                if(onItemClickListener != null){
                    onItemClickListener.onOpenClick(feedItem);
                }
                break;
            case R.id.btn_star:
                if(onItemClickListener != null){
                    onItemClickListener.onStarClick(feedItem);
                }
                break;
            case R.id.btn_rating:
                if(onItemClickListener != null){
                    onItemClickListener.onRatingClick(feedItem);
                }
                break;
            case R.id.btn_report:
                if (onItemClickListener != null) {
                    onItemClickListener.onReportClick(feedItem);
                }
                break;
            case R.id.btn_cancel:
                if (onItemClickListener != null) {
                    onItemClickListener.onCancelClick(feedItem);
                }
                break;
        }

    }

    public interface OnMoreContextMenuItemClickListener {
        public void onReportClick(int feedItem);

        public void onOpenClick(int feedItem);

        public void onStarClick(int feedItem);

        public void onRatingClick(int feedItem);

        public void onCancelClick(int feedItem);
    }
}